package com.hg.design.behavior.iterator.biancheng.ex2;

import java.util.ArrayList;
import java.util.List;

//具体迭代器：婺源景点
public class WyViewSpotIterator implements ViewSpotIterator {
    private List<WyViewSpot> list;
    private int index;
    protected WyViewSpot wyViewSpot;

    public WyViewSpotIterator(ArrayList<WyViewSpot> list) {
        this.list = list;
        this.index = 0;
    }

    @Override
    public boolean hasNext() {
        return index < this.list.size() - 1;
    }

    @Override
    public boolean hasPrevious() {
        return index > 1;
    }

    @Override
    public WyViewSpot first() {
        index = 0;
        return this.list.get(index);
    }

    @Override
    public WyViewSpot next() {
        return this.hasNext() ? this.list.get(++index) : this.list.get(index);
    }

    @Override
    public WyViewSpot previous() {
        return this.hasPrevious() ? this.list.get(--index) : this.list.get(index);
    }

    @Override
    public WyViewSpot last() {
        index = this.list.size() - 1;
        return this.list.get(index);
    }
}
